package com.guofen.controller.sjq;

import com.guofen.pojo.SjqFlocculationProduceCheck;
import com.guofen.pojo.SjqFlocculationProduceElectricity;
import com.guofen.service.sjq.SjqFlocculationProduceCheckService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/sjq/flocculationProduceCheck")
@Controller
@Api(tags = "SjqFlocculationProduceCheckController", description = "絮凝 生产现场 记录表（设备检查）")
public class SjqFlocculationProduceCheckController {

    @Autowired
    private SjqFlocculationProduceCheckService sjqFlocculationProduceCheckService;

    @ApiOperation("添加记录（操作人）")
    @RequestMapping(value = "/addOperationalForm", method = RequestMethod.POST)
    @ResponseBody
    public Result addOperationalForm(@ApiParam(name = "equipment_name", value = "设备名称", required = true) @RequestParam String equipment_name,
                                     @ApiParam(name="is_normal",value="是否正常",required=true) @RequestParam String is_normal,
                                     @ApiParam(name = "remarks", value = "问题备注", required = true) @RequestParam String remarks,
                                     @ApiParam(name = "operator", value = "操作人", required = true) @RequestParam String operator){
        if (sjqFlocculationProduceCheckService.addOperationalForm(equipment_name, is_normal, remarks, operator))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("添加记录（检查人）")
    @RequestMapping(value = "/addExaminationalForm", method = RequestMethod.POST)
    @ResponseBody
    public Result addExaminationalForm(@ApiParam(name = "id", value = "id", required = true) @RequestParam String id,
                                       @ApiParam(name = "remarks", value = "问题备注", required = true) @RequestParam String remarks,
                                       @ApiParam(name = "inspector", value = "检查人", required = true) @RequestParam String inspector){

        if (sjqFlocculationProduceCheckService.addExaminationalForm(id,inspector,remarks))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("查找当天的所有设备检查记录")
    @RequestMapping(value = "/findEquipList",method = RequestMethod.GET)
    @ResponseBody
    public Result findEquipList() {
        return  ResultGenerator.genSuccessResult(sjqFlocculationProduceCheckService.findEquipList());
    }

    @ApiOperation("查找所有故障设备")
    @RequestMapping(value = "/findFaultEquipList",method = RequestMethod.GET)
    @ResponseBody
    public Result findFaultEquipList() {
        return  ResultGenerator.genSuccessResult(sjqFlocculationProduceCheckService.findFaultEquipList());
    }

    @ApiOperation("删除记录")
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(sjqFlocculationProduceCheckService.delete(id));
    }

    @ApiOperation("修改记录")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Result update(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id,
                         @ApiParam(name="equipmentName",value="设备名称",required=true) @RequestParam String equipmentName,
                         @ApiParam(name="isNormal",value="是否正常",required=true) @RequestParam String isNormal,
                         @ApiParam(name="remarks",value="备注",required=true) @RequestParam String remarks,
                         @ApiParam(name="operator",value="操作人",required=true) @RequestParam String operator,
                         @ApiParam(name="inspector",value="检查人",required=true) @RequestParam String inspector,
                         @ApiParam(name="isForm",value="",required=true) @RequestParam Boolean isForm,
                         @ApiParam(name="reserve1",value="",required=true) @RequestParam String reserve1) {
        SjqFlocculationProduceCheck record = new SjqFlocculationProduceCheck();
        record.setId(id);
        record.setEquipmentName(equipmentName);
        record.setIsNormal(isNormal);
        record.setRemarks(remarks);
        record.setOperator(operator);
        record.setInspector(inspector);
        record.setIsForm(isForm);
        record.setReserve1(reserve1);
        return ResultGenerator.genSuccessResult(sjqFlocculationProduceCheckService.update(record));
    }

    @ApiOperation("查找记录")
    @RequestMapping(value = "/select",method = RequestMethod.POST)
    @ResponseBody
    public Result select(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间") Long startTime,
                         @ApiParam(name="endTime",value="截止时间") Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(sjqFlocculationProduceCheckService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(sjqFlocculationProduceCheckService.getByTime(pageSize, currentPage, startTime, endTime));
    }
}
